package org.alps.pattern.singleton.threadlocal;

/**
 * 注册式单例（容器式）
 * 伪线程安全
 * @date 2021-04-30
 * @author zkw
 */
public class ThreadLocalSingleton {
    private ThreadLocalSingleton(){}

    private static final ThreadLocal<ThreadLocalSingleton> Thread_LOCAL_INSTANCE =
            new ThreadLocal<ThreadLocalSingleton>() {
                @Override
                protected ThreadLocalSingleton initialValue() {
                    return new ThreadLocalSingleton();
                }
            };

    public static ThreadLocalSingleton getInstance() {
        return Thread_LOCAL_INSTANCE.get();
    }
}
